<?php
    require './封装.php';
    $str=[
        "host"=>"127.0.0.1",
        "root"=>"root",
        "pwd"=>"root",
        "database"=>"php07",
        "port"=>"8080"
    ];
    $db=new Db($str);
    // var_dump($db);
    // $sql="insert into good values (null,'zhangsan','41')";
    // $sql="select * from good";
    // var_dump($db->execute($sql));
    // var_dump($db->select($sql));
    $sql="select count(*) from products";
    $total=$db->select($sql)[0][0];
    var_dump($total);
    $size=10;
    $totalpage=ceil($total/$size);
   
    

    // $currentpage=isset($_GET['currentpage'])?$_GET['currentpage']:1;
    $currentpage=$_GET['currentpage']??1;
    $currentpage=$currentpage<1?1:$currentpage;
    $currentpage=$currentpage>$totalpage?$totalpage:$currentpage;
    $start=($currentpage-1)*$size;
    $sql="select * from products limit $start , $size";
    $data=$db->select($sql,'assoc');
    // var_dump($data)
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table{
            width:780px;
            border: 1px solid #000;
            border-collapse: collapse;
        }
        td,th{
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <table>
    <tr>
        <th>编号</th>
        <th>商品名称</th>
        <th>规格</th>
        <th>价格</th>
    </tr>
    <?php foreach($data as $v): ?>
    <tr>
    
        <td><?php echo $v['proID']?></td>
        <td><?php echo $v['proname']?></td>
        <td><?php echo $v['proguige']?></td>
        <td><?php echo $v['proprice']?></td>
    </tr>
    <?php endforeach; ?>
    </table>
    <a href="./分页.php?currentpage=1">首页</a>
    <a href="./分页.php?currentpage=<?php echo $currentpage-1;?>">上一页</a>
    <?php
    for($i=1;$i<=$totalpage;$i++){
            echo "<a href='./分页.php?currentpage=$i'>$i</a>\t";
        }
    ?>
    <a href="./分页.php?currentpage=<?php echo $currentpage+1;?>">下一页</a>
    <a href="./分页.php?currentpage=<?php echo  $totalpage;?>">尾页</a>
</body>
</html>
